package com.ctrip.corp.obt.shard.utils;////
//// Source code recreated from a .class file by IntelliJ IDEA
//// (powered by Fernflower decompiler)
////
//
//package cn.astana.sharding.utils;
//
//
//
//import com.sun.org.apache.xml.internal.security.utils.Base64;
//
//import javax.crypto.BadPaddingException;
//import javax.crypto.Cipher;
//import javax.crypto.IllegalBlockSizeException;
//import javax.crypto.KeyGenerator;
//import javax.crypto.NoSuchPaddingException;
//import javax.crypto.SecretKey;
//import javax.crypto.spec.SecretKeySpec;
//import java.nio.charset.StandardCharsets;
//import java.security.InvalidKeyException;
//import java.security.NoSuchAlgorithmException;
//import java.security.SecureRandom;
//
//public class AESEncryptUtils {
//    private static final String SALT = "dbshard";
//    private static int length = 128;
//
//    public AESEncryptUtils() {
//    }
//
//    private static byte[] encrypt(String content, String password) throws Exception {
//        KeyGenerator kgen = KeyGenerator.getInstance("AES");
//        SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
//        secureRandom.setSeed(password.getBytes());
//        kgen.init(length, secureRandom);
//        SecretKey secretKey = kgen.generateKey();
//        byte[] enCodeFormat = secretKey.getEncoded();
//        SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
//        Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
//        byte[] byteContent = content.getBytes(StandardCharsets.UTF_8);
//        cipher.init(1, key);
//        return cipher.doFinal(byteContent);
//    }
//
//    private static byte[] decrypt(byte[] content, String password) throws Exception {
//        KeyGenerator kgen = KeyGenerator.getInstance("AES");
//        SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
//        secureRandom.setSeed(password.getBytes());
//        kgen.init(length, secureRandom);
//        SecretKey secretKey = kgen.generateKey();
//        byte[] enCodeFormat = secretKey.getEncoded();
//        SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
//        Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
//        cipher.init(2, key);
//        return cipher.doFinal(content);
//    }
//
//    public static byte[] encrypt2(String content, String password) {
//        try {
//            SecretKeySpec key = new SecretKeySpec(password.getBytes(), "AES");
//            Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
//            byte[] byteContent = content.getBytes(StandardCharsets.UTF_8);
//            cipher.init(1, key);
//            return cipher.doFinal(byteContent);
//        } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException ex) {
//            ex.printStackTrace();
//        }
//
//        return null;
//    }
//
//    public static String encrypt2Str(String content) throws Exception {
//        return encrypt2Str(content, SALT);
//    }
//
//    public static String encrypt2Str(String content, String password) throws Exception {
//        byte[] encryptResult = encrypt(content, password);
//        return Base64.encode(encryptResult);
//    }
//
//    public static String decrypt2Str(String content) throws Exception {
//        return decrypt2Str(content, SALT);
//    }
//
//    public static String decrypt2Str(String content, String password) throws Exception {
//        byte[] decryptResult = decrypt(Base64.decode(content), password);
//        return new String(decryptResult, StandardCharsets.UTF_8);
//    }
//}
